
package com.backsectionmodule.servlet;
import com.backsectionmodule.bean.TbBackSection;
import com.backsectionmodule.dao.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbBackSectionServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        String backSectionCode=request.getParameter("backSectionCode");
        String projectCode=request.getParameter("projectCode");
        int backSectionType=Integer.parseInt(request.getParameter("backSectionType"));
        int backSectionSequence=Integer.parseInt(request.getParameter("backSectionSequence"));
        double backSectionAmount=Double.valueOf(request.getParameter("backSectionAmount"));
        String backSectionCompanyName=request.getParameter("backSectionCompanyName");
        String backSectionTime=request.getParameter("backSectionTime");

            if(new TbBackSectionDAO().add(new TbBackSection(backSectionCode,projectCode,backSectionType,backSectionSequence,backSectionAmount,backSectionCompanyName,backSectionTime))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
             request.getSession(true).setAttribute("tbBackSectionList",new TbBackSectionDAO().getTbBackSectionAll());
            response.sendRedirect("BackSectionModule/TbBackSectionList.jsp");
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_BackSection", "BackSectionId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
             request.getSession(true).setAttribute("tbBackSectionList",new TbBackSectionDAO().getTbBackSectionAll());
            response.sendRedirect("BackSectionModule/TbBackSectionList.jsp");
        }
        if("edit".equals(method)){
        int backSectionId=Integer.parseInt(request.getParameter("backSectionId"));
        String backSectionCode=request.getParameter("backSectionCode");
        String projectCode=request.getParameter("projectCode");
        int backSectionType=Integer.parseInt(request.getParameter("backSectionType"));
        int backSectionSequence=Integer.parseInt(request.getParameter("backSectionSequence"));
        double backSectionAmount=Double.valueOf(request.getParameter("backSectionAmount"));
        String backSectionCompanyName=request.getParameter("backSectionCompanyName");
        String backSectionTime=request.getParameter("backSectionTime");

            if(new TbBackSectionDAO().edit(new TbBackSection(backSectionId,backSectionCode,projectCode,backSectionType,backSectionSequence,backSectionAmount,backSectionCompanyName,backSectionTime))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
             request.getSession(true).setAttribute("tbBackSectionList",new TbBackSectionDAO().getTbBackSectionAll());
            response.sendRedirect("BackSectionModule/TbBackSectionList.jsp");
        }
        if ("list".equals(method)) {
             request.getSession(true).setAttribute("tbBackSectionList",new TbBackSectionDAO().getTbBackSectionAll());
            response.sendRedirect("BackSectionModule/TbBackSectionList.jsp");
        	}
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbBackSection",new TbBackSectionDAO().getTbBackSectionByBackSectionId(Integer.parseInt(request.getParameter("backSectionId"))));
            response.sendRedirect("BackSectionModule/TbBackSectionOperate.jsp");
    	}
        if("showadd".equals(method)){
            
            request.getSession(true).removeAttribute("tbBackSection");
            response.sendRedirect("BackSectionModule/TbBackSectionOperate.jsp");
        }
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
